<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ReceiptInfo;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class ReceiptInfoController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ReceiptInfo(), function (Grid $grid) {

            $grid->scrollbarX();
            $grid->withBorder();
            $grid->addTableClass(['table-text-center']);



            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('is_default');
            $grid->column('type');

            $grid->column('header');
            $grid->column('company_addr');
            $grid->column('company_phone');
            $grid->column('bank_name');
            $grid->column('bank_number');
            $grid->column('tax_type');
            $grid->column('tax_user_id');
            $grid->column('tax_cert');
            $grid->column('receive_user');
            $grid->column('receive_mobile');
            $grid->column('receive_addr');
            $grid->column('remark');

            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            /**
             * 按钮控制.
             */
            // @permissions
            if (!Admin::user()->can('user-create')) {
                $grid->disableCreateButton();
                // $grid->disableQuickCreateButton();
            }

            // @permissions
            if ((!Admin::user()->can('user-update'))) {
                $grid->disableEditButton();
                // $grid->disableQuickEditButton();
            }
            // @permissions
            if (!Admin::user()->can('user-delete')) {
                $grid->disableDeleteButton();
            }

            // @permissions
            if (!Admin::user()->can('user-view')) {
                $grid->disableViewButton();
            }

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ReceiptInfo(), function (Show $show) {
            $show->field('id');
            $show->field('id');
            $show->field('user_id');
            $show->field('is_default');
            $show->field('type');

            $show->field('header');
            $show->field('company_addr');
            $show->field('company_phone');
            $show->field('bank_name');
            $show->field('bank_number');
            $show->field('tax_type');
            $show->field('tax_user_id');
            $show->field('tax_cert');
            $show->field('receive_user');
            $show->field('receive_mobile');
            $show->field('receive_addr');
            $show->field('remark');

            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ReceiptInfo(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('is_default');
            $form->text('type');

            $form->text('header');
            $form->text('company_addr');
            $form->text('company_phone');
            $form->text('bank_name');
            $form->text('bank_number');
            $form->text('tax_type');
            $form->text('tax_user_id');
            $form->text('tax_cert');
            $form->text('receive_user');
            $form->text('receive_mobile');
            $form->text('receive_addr');
            $form->text('remark');
          

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
